package cn.stylefeng.guns.modular.rm;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.stylefeng.guns.base.utils.StringUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.List;

/**
 * @Description rm比赛结果
 * @Author xiesm
 * @Date 2024/5/23 15:38
 **/
public class RmGameResult {
    public static void main(String[] args) {
        getHtmlBody();
    }

    public static String getHtmlBody() {
        String body = getHtmlBody("2024-06-02");
        Document document = Jsoup.parse(body);
        Elements game_trade = document.getElementsByClass("game_trade");
        String str = "{}\t{}\t{}\t{}\t{}\t{}\t{}";
        for (int i = 0; i < game_trade.size(); i++) {
            Element element = game_trade.get(i);
            String onclick = element.attr("onclick");
            List<String> strs = StringUtil.replace(onclick, "getGameData");
            System.out.println(StrUtil.format(str,
                    strs.get(0),
                    strs.get(1),
                    strs.get(2),
                    strs.get(3),
                    strs.get(4),
                    strs.get(5),
                    strs.get(6)));
        }
        return null;
    }

    public static String getHtmlBody(String date) {
        String url = "http://124.222.75.100:8089/cp/rmmarket?type=3&date={}";
        url = StrUtil.format(url, date);
        String body = HttpUtil.createGet(url).execute().body();
        return body;
    }
}
